class Tree:
    def __init__(self, val, flag):
        self.val = val
        self.neighbors = {}
        self.flag = flag
        self.content = None


class FileSystem(object):

    def __init__(self):
        self.root = Tree('#', 0)

    def ls(self, path):
        """
        :type path: str
        :rtype: List[str]
        """
        if path == '/':
            files = list(self.root.neighbors.keys())
            files.sort()
            return files
        else:
            s = path.split('/')[1:]
            node = self.root
            for i in range(len(s)):
                node = node.neighbors[s[i]]
            if node.flag == 1:
                return [node.val]
            else:
                files = list(node.neighbors.keys())
                files.sort()
                return files

    def mkdir(self, path):
        """
        :type path: str
        :rtype: None
        """
        s = path.split('/')[1:]
        node = self.root
        for i in range(len(s)):
            if s[i] not in node.neighbors:
                new_node = Tree(s[i], 0)
                node.neighbors[s[i]] = new_node
                node = new_node
            else:
                node = node.neighbors[s[i]]

    def addContentToFile(self, filePath, content):
        """
        :type filePath: str
        :type content: str
        :rtype: None
        """
        s = filePath.split('/')[1:]
        node = self.root
        for i in range(len(s) - 1):
            if s[i] not in node.neighbors:
                new_node = Tree(s[i], 0)
                node.neighbors[s[i]] = new_node
                node = new_node
            else:
                node = node.neighbors[s[i]]
        if s[-1] in node.neighbors:
            node = node.neighbors[s[-1]]
            node.content += content
        else:
            new_node = Tree(s[-1], 1)
            node.neighbors[s[-1]] = new_node
            node = new_node
            node.content = content

    def readContentFromFile(self, filePath):
        """
        :type filePath: str
        :rtype: str
        """
        s = filePath.split('/')[1:]
        node = self.root
        for i in range(len(s)):
            node = node.neighbors[s[i]]
        return node.content
